package lab03.test08;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Test08 {
    public static void main(String[] args) {
        String soure1 = "D:\\1.txt";
        String soure2 = "d:\\2.txt";
        String target = "d:\\3.txt";

        FileInputStream fileInputStream = null;
        FileInputStream fileInputStreamnext = null;

        FileOutputStream fileOutputStream = null;

        try {
            fileInputStream = new FileInputStream(soure1);
            fileInputStreamnext = new FileInputStream(soure2);

            fileOutputStream = new FileOutputStream(target);
            int line ;
            int linenext;
            int a;

            while((a=(line= fileInputStream.read())>(linenext=fileInputStreamnext.read())?line:linenext) != -1){

                if(line != -1){
                fileOutputStream.write(line);
                }

                if(linenext != -1){
                fileOutputStream.write((char)linenext);
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileInputStream.close();
                fileInputStreamnext.close();
                fileOutputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
